//验证挂号以及修改、保存
$(function(){
    
    $("div#save :input").click(function(){
        var clinic_Id = $("select#clinic_Id").val() ;
        var register_DateTime = $("select#register_DateTime").val() ;
        var doctor_Id = $("select#doctor_Id").val() ;
        var register_Status = $("select#register_Status").val() ;
        var register_Sysptom = $("#register_Sysptom").val() ;
        var register_Remark = $("#register_Remark").val() ;
        
        if(clinic_Id == "" && doctor_Id == null && register_DateTime == null){
           var errorMsg = "请选择有效的门诊室医生预约时间" ;
           alert(errorMsg) ;
           return false ;
        }
        if(doctor_Id == "" && register_DateTime == ""){
           var errorMsg = "请选择有效的门诊室医生预约时间" ;
           alert(errorMsg) ;
           return false ;
        }
        if(doctor_Id == ""){
           var errorMsg = "请选择有效的门诊室医生预约时间" ;
           alert(errorMsg) ;
           return false ;
        }
        if(register_DateTime == ""){
           var errorMsg = "请选择有效的门诊室医生预约时间" ;
           alert(errorMsg) ;
           return false ;
        }
        if(register_Status == ""){
           var errorMsg = "请选择有效的就诊状态" ;
           alert(errorMsg) ;
           return false ;
        }
        
        if(register_Sysptom == "" ){
            var errorMsg = "请填写症状描述" ;
            alert(errorMsg) ;
            return false ;
        }
        
        var errorMsg ;  
        $.ajax({
			type: "POST",
			url: "saveRegister.do?",
			data:"register_DateTime="+register_DateTime+"&register_Status="+register_Status+"&register_Sysptom="+register_Sysptom+"&register_Remark="+register_Remark+"&clinic_Id="+clinic_Id+"&doctor_Id="+doctor_Id ,
			dataType: 'text',
			async: false,
			error:function(data){
				
			},
			success: function(data){
			   if(data == "saveSuccess"){
			        errorMsg = "保存成功" 
			        alert(errorMsg) ; 
			   }else{
			        errorMsg = "保存失败" ;
			        alert(errorMsg) ;
			   }  
            }										
	
		});
		if(errorMsg == "保存失败"){
		   return false ;
		}
		return true ;
    }) ;
    var msg ;
    $("div#update :input").click(function(){
        
        var register_Id = $(".update").attr("name") ;
        var clinic_Id = $("select#clinic_Id").val() ;
        var register_DateTime = $("select#register_DateTime").val() ;
        var doctor_Id = $("select#doctor_Id").val() ;
        var register_Status = $("select#register_Status").val() ;
        var register_Sysptom = $("#register_Sysptom").val() ;
        var register_Remark = $("#register_Remark").val() ;
        $.ajax({
			type: "POST",
			url: "updateRegister.do?",
			data:"register_Id="+register_Id+"&register_DateTime="+register_DateTime+"&register_Status="+register_Status+"&register_Sysptom="+register_Sysptom+"&register_Remark="+register_Remark+"&clinic_Id="+clinic_Id+"&doctor_Id="+doctor_Id ,
			dataType: 'text',
			async: false,
			error:function(data){
				
			},
			success: function(data){
			      msg = data ;
			      if(msg == "updateSuccess"){
			         msg = "修改成功" ;
			         alert(msg) ;
			      }else{
			         msg = "修改失败" ;
			         alert(msg) ;
			      }
			         
            }										
	
		});
		if(msg == "修改失败"){
		    return false ;
		}
		$("#update").hide() ; //修改按钮不可见
        $("#save").show() ; //保存按钮可见
        return true ;
    }) ;
}) ;